package com.nixsolutions.servlet;

import com.nixsolutions.bean.User;
import com.nixsolutions.dao.HibernateUserDao;
import com.nixsolutions.dao.UserDao;
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author yakimovich
 */
public class RemoveUser extends HttpServlet {

    private RequestDispatcher dispatcher;
    private static org.apache.commons.logging.Log logger 
            = LogFactory.getLog(RemoveUser.class);

    @Override
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {

        HttpSession session = request.getSession();

        UserDao userDao = new HibernateUserDao();
        long id = Long.parseLong(request.getParameter("id"));
        String login = request.getParameter("login");

        User user = new User();
        user.setId(id);
        user.setLogin(login);
        userDao.remove(user);

        List<User> list = userDao.findAll();
        request.setAttribute("users", list);
        dispatcher = getServletContext()
                .getRequestDispatcher("/adminPage.jsp");
        dispatcher.forward(request, response);
    }
}